package com.tsing.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.tsing.cloud.myhandler.CustomerBlockHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TheTsing
 * @version 1.0
 * @date 2021/11/15 11:52
 */
@RestController
public class RateLimitController {

    /**
     * 客户自定义限流处理逻辑：1、写在一个类里 2、解耦，写在一个全局处理类里
     */
    @GetMapping("/byReSource")
    @SentinelResource(value = "byReSource", blockHandler = "handlerException")
    public String byReSource() {
        return "------按资源名称限流测试";
    }

    public String handlerException(BlockException exception) {
        return "------服务不可用";
    }

    @GetMapping("/rateLimit/customerBlockHandler")
    @SentinelResource(value = "customerBlockHandler", blockHandlerClass = CustomerBlockHandler.class, blockHandler = "handlerException2")
    public String customerBlockHandler() {
        return "------按客户自定义";
    }

}
